<template>
  <div class="like-container">
    <div class="like-header">
      <div class="like-title">你觉得什么让你满意？</div>

      <div class="like-left">
        <img :src="Copy" class="like_Copy" alt="" @click="copyId" />
        <!-- <div class="like-id" @click="copyId">复制反馈ID</div> -->
        <div>
          <div class="like-slot"></div>
        </div>
        <el-icon class="like-close" @click="close"><Close /></el-icon>
      </div>
    </div>

    <div class="like-body">
      <div class="like-body-wrapper">
        <div
          v-for="item in list"
          class="like-body-label"
          :class="{ active: array.includes(item.value) }"
          @click="handleClick(item.value)"
        >
          {{ item.label }}
        </div>
      </div>
      <el-button
        type="primary"
        class="like-submit"
        size="small"
        v-if="!footerFlag"
        @click="handleSubmit"
        >提交</el-button
      >
    </div>

    <div class="like-footer" v-if="footerFlag">
      <el-input
        v-model="input"
        placeholder="(可选) 告诉我们更多关于你的使用体验"
        class="like-input"
      />
      <el-button type="primary" class="like-submit" size="small" @click="handleSubmit"
        >提交</el-button
      >
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import Copy from '@/assets/png/copy.png'
import { ElMessage } from 'element-plus'

const props = defineProps({
  handleReset: Function
})

onMounted(() => {
  init()
})

const init = () => {
  input.value = ''
  footerFlag.value = false
  array.value = []
}

const list = ref([
  { label: '内容准确', value: 1 },
  { label: '易于理解', value: 2 },
  { label: '内容完善', value: 3 },
  { label: '其他', value: 4 }
])

const input = ref('')
const array = ref([])
const footerFlag = ref(false)

const handleClick = (value: Number) => {
  if (value == 4) {
    footerFlag.value = !footerFlag.value
  }

  if (array.value.includes(value)) {
    array.value.splice(array.value.indexOf(value), 1)
  } else {
    array.value.push(value)
  }
}

const close = () => {
  props.handleReset()
}

const handleSubmit = () => {
  if (array.value.length === 0 && input.value === '') {
    ElMessage({
      message: '请选择满意类型或输入其他反馈',
      type: 'warning'
    })
    return
  }
  props.handleReset()
  ElMessage({
    message: '感谢你让我们变得更好',
    type: 'warning'
  })
}

const copyId = () => {
  ElMessage({
    message: '反馈ID已复制',
    type: 'success'
  })
}
</script>
<style scoped lang="less">
.active {
  color: #252525 !important;
  background-color: #f5f5f5;
}
.like-container {
  display: flex;
  flex-direction: column;

  .like-header {
    display: flex;
    justify-content: space-between;

    .like-title {
      font-size: 14px;
    }

    .like-left {
      display: flex;
      height: 20px;

      .like_Copy {
        width: 20px;
        margin-right: 5px;
        cursor: pointer;
        width: 15px;
        height: 15px;
        margin-top: 3px;
      }

      .like-id {
        cursor: pointer;
        font-size: 14px;
      }

      .like-slot {
        width: 2px;
        background-color: #ccc;
        height: 65%;
        margin: 4px 15px 0 15px;
      }

      .like-close {
        margin-top: 2.5px;
        cursor: pointer;
      }
    }
  }

  .like-body {
    display: flex;
    margin: 15px 0;
    justify-content: space-between;

    .like-submit {
      background-color: #004ad9;
      margin-top: 5px;
    }

    .like-body-wrapper {
      width: 100%;
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      gap: 5px; /* 同时设置行和列间距 */
      row-gap: 5px; /* 仅设置行间距（垂直方向） */
    }
    .like-body-label {
      display: flex;
      align-items: center;
      padding: 5px 15px;
      border: 1px solid #ccc;
      margin-right: 10px;
      border-radius: 10px;
      cursor: pointer;
      color: #ccc;
      transition: all 0.3s ease;
      font-size: 12px;
    }

    .like-body-label:hover {
      color: #a0a0a0;
      background-color: #f5f5f5;
    }
  }

  .like-footer {
    display: flex;
    .like-input {
      width: 100%;
    }
    .like-submit {
      background-color: #004ad9;
      margin-left: 20px;
    }
  }
}

:deep(.el-input),
:deep(.el-input__wrapper) {
  background-color: #f5f5f5 !important;
  border: 0 !important;
  box-shadow: 0 0 0 1px #f5f5f5 inset !important;
  border-radius: 10px !important;
}
:deep(.el-input__inner::placeholder) {
  padding: 0 5px;
}
</style>
